var RE_DESKRIPSI = /.{5,}/;
var RE_JUDUL = /.{5,}/;
var RE_KEYWORD = /.{3,}/;
var RE_PROFIL = /^.+\.((jpg)|(JPG)|(png)|(PNG)|(bmp)|(BMP)|(JPEG)|(JPEG))$/;
var RE_TANGGAL = /^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))$/;

function check(form)
{

	var deskripsi = form.description.value;
        var judul = form.title.value;
	var keyword = form.keyword.value;
	var foto = form.uploadFile.value;
	var tanggal = form.dateTaken.value;
	var errors = [];
	
	if (!RE_DESKRIPSI.test(deskripsi))
	{
		errors[errors.length] = "deskripsi foto tidak valid";	
	}
	if (!RE_KEYWORD.test(keyword))
	{
		errors[errors.length] = "kata kunci tidak valid";	
	}
	if (!RE_PROFIL.test(foto))
	{
		errors[errors.length] = "file foto tidak valid";
	}
	if(!RE_TANGGAL.test(tanggal))
	{
		errors[errors.length] = "Tanggal foto tidak valid";
	}
        if(!RE_JUDUL.test(judul))
	{
		errors[errors.length] = "Judul foto tidak valid";
	}
	if (errors.length > 0)
	{
  		reportErrors(errors);
  		return false;
	}
 
	return true;
}

function reportErrors(errors)
{
 var msg = "Ada beberapa kesalahan\n";
 for (var i = 0; i<errors.length; i++) {
  var numError = i + 1;
  msg += "\n" + numError + ". " + errors[i];
 }
 alert(msg);
}